#define store_x sw
#define load_x lw
#define portWORD_SIZE 4
#define portCONTEXT_SIZE ( 32 * portWORD_SIZE )

.global xPortStartFirstTask

.global xPortSetInterruptMask

.extern pxCurrentTCB

.align 8
.func
xPortStartFirstTask:
    addi a0,x0,0
    csrrw x0,mie,a0
    load_x  t0, pxCurrentTCB
    load_x  t0,0(t0)
	addi sp,t0,0//恢复sp
    load_x  a1, 31 * portWORD_SIZE( sp )//获取mepc
	csrrw x0,mepc,a1//恢复mepc

    load_x  x1, 0 * portWORD_SIZE( sp )     /* ra */
    load_x  x2, 1 * portWORD_SIZE( sp )     /* sp */
	load_x  x3, 2 * portWORD_SIZE( sp )		/* gp */
	load_x  x4, 3 * portWORD_SIZE( sp )		/* tp */
	load_x  x5, 4 * portWORD_SIZE( sp )		/* t0 */
	load_x  x6, 5 * portWORD_SIZE( sp )		/* t1 */
	load_x  x7, 6 * portWORD_SIZE( sp )		/* t2 */
	load_x  x8, 7 * portWORD_SIZE( sp )	/* s0/fp */
	load_x  x9, 8 * portWORD_SIZE( sp )	/* s1 */
	load_x  x10, 9 * portWORD_SIZE( sp )	/* a0 */
	load_x  x11, 10 * portWORD_SIZE( sp )	/* a1 */
	load_x  x12, 11 * portWORD_SIZE( sp )	/* a2 */
	load_x  x13, 12 * portWORD_SIZE( sp )	/* a3 */
	load_x  x14, 13 * portWORD_SIZE( sp )	/* a4 */
	load_x  x15, 14 * portWORD_SIZE( sp )	/* a5 */
	load_x  x16, 15 * portWORD_SIZE( sp )	/* a6 */
	load_x  x17, 16 * portWORD_SIZE( sp )	/* a7 */
	load_x  x18, 17 * portWORD_SIZE( sp )	/* s2 */
	load_x  x19, 18 * portWORD_SIZE( sp )	/* s3 */
	load_x  x20, 19 * portWORD_SIZE( sp )	/* s4 */
	load_x  x21, 20 * portWORD_SIZE( sp )	/* s5 */
	load_x  x22, 21 * portWORD_SIZE( sp )	/* s6 */
	load_x  x23, 22 * portWORD_SIZE( sp )	/* s7 */
	load_x  x24, 23 * portWORD_SIZE( sp )	/* s8 */
	load_x  x25, 24 * portWORD_SIZE( sp )	/* s9 */
	load_x  x26, 25 * portWORD_SIZE( sp )	/* s10*/
	load_x  x27, 26 * portWORD_SIZE( sp )	/* s11 */
	load_x  x28, 27 * portWORD_SIZE( sp )	/* t3 */
	load_x  x29, 28 * portWORD_SIZE( sp )	/* t4 */
    load_x  x30, 29 * portWORD_SIZE( sp )	/* t5 */
    load_x  x31, 30 * portWORD_SIZE( sp )	/* t6 */
    addi a1,x0,0
    csrrw x0,mcause,x0
    lui a1,%hi(0xffffffff)
    addi a1,a1,%lo(0xffffffff)
    csrrw x0,mie,a1
    
	addi sp, sp, portCONTEXT_SIZE
	mret
	.endfunc

.align 8
.func
 xPortSetInterruptMask:
    addi sp,sp,-4
    sw a1,0(sp)
    addi a1,x0,0
    csrrw a0,mie,a1
    lw a1,0(sp)
    addi sp,sp,4
    ret
    .endfunc